import 'package:flutter/material.dart';
import 'package:flutter_smart_heating/ui/ui.dart';

class InputItemView extends StatelessWidget {
  const InputItemView({
    super.key,
    this.render = false,
    this.controller,
    this.focusNode,
    this.onChanged,
    this.onSubmitted,
    this.icon,
    this.prefix,
    this.suffix,
    this.obscureText = false,
    this.placeholder = '',
    this.maxLength,
    this.keyboardType,
    this.margin,
    this.padding,
    this.height,
    this.background,
    this.textColor,
    this.readOnly,
    this.child,
  });
  final bool render;
  final TextEditingController? controller;
  final FocusNode? focusNode;
  final Function(String value)? onSubmitted;
  final Function(String value)? onChanged;
  final Widget? prefix;
  final Widget? suffix;
  final bool obscureText;
  final String placeholder;
  final IconData? icon;
  final int? maxLength;
  final TextInputType? keyboardType;
  final EdgeInsetsGeometry? margin;
  final EdgeInsetsGeometry? padding;
  final double? height;
  final Color? background;
  final Color? textColor;
  final bool? readOnly;
  final Widget? child;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: margin ?? const EdgeInsets.only(bottom: UiTheme.spacingX),
      height: height ?? UiTheme.buttonHeight,
      child: ClipRRect(
        borderRadius: BorderRadius.circular(5),
        child: UiPanel(
          padding: padding ?? const EdgeInsets.symmetric(horizontal: 10),
          child: Row(
            children: [
              prefix ?? Container(),
              if (icon != null) Icon(icon, color: Colors.grey),
              if (icon != null) const SizedBox(width: 5),
              Expanded(
                child: render
                    ? child ??
                        UiInput(
                          controller: controller,
                          focusNode: focusNode,
                          obscureText: obscureText,
                          maxLength: maxLength,
                          keyboardType: keyboardType,
                          placeholder: placeholder,
                          onSubmitted: onSubmitted,
                          onChanged: onChanged,
                          textColor: textColor,
                          readOnly: readOnly ?? false,
                        )
                    : Text(
                        placeholder,
                        style: TextStyle(
                          color: UiTheme(context).infoColor,
                          fontSize: 15,
                        ),
                      ),
              ),
              suffix ?? Container()
            ],
          ),
        ),
      ),
    );
  }
}
